import aiomysql
import asyncio

async def fetch_data():
    # 创建连接池
    pool = await aiomysql.create_pool(host='localhost',
                                      port=3306,
                                      user='root', password='A7#mZ9!pL3$q', db='test')

    async with pool.acquire() as conn:
        async with conn.cursor() as cursor:
            await cursor.execute('SELECT * FROM user')
            result = await cursor.fetchall()
            print(result)

    # 关闭连接池，不再接收新的连接请求
    pool.close()
    # 等待连接池完全关闭，确保所有连接都已释放
    await pool.wait_closed()

# 运行协程
asyncio.run(fetch_data())